set(CMAKE_VERBOSE_MAKEFILE yes)

set(MEDOOZE_SOURCES
        ../../src/xdtls_srtp.cpp
        ../../src/xdtls_srtp.h
        ../../src/fp_buf.hpp
        ../../src/fp_buf.cpp
        ../../src/media_probe.hpp
        ../../src/media_probe.cpp
        mod/rtp/RTCPApp.cpp
        mod/rtp/RTCPApp.h
        mod/rtp/RTCPBye.cpp
        mod/rtp/RTCPBye.h
        mod/rtp/RTCPCommonHeader.cpp
        mod/rtp/RTCPCommonHeader.h
        mod/rtp/RTCPCompoundPacket.cpp
        mod/rtp/RTCPCompoundPacket.h
        mod/rtp/RTCPExtendedJitterReport.cpp
        mod/rtp/RTCPExtendedJitterReport.h
        mod/rtp/RTCPFullIntraRequest.cpp
        mod/rtp/RTCPFullIntraRequest.h
        mod/rtp/RTCPNACK.cpp
        mod/rtp/RTCPNACK.h
        mod/rtp/RTCPPacket.cpp
        mod/rtp/RTCPPacket.h
        mod/rtp/RTCPPayloadFeedback.cpp
        mod/rtp/RTCPPayloadFeedback.h
        mod/rtp/RTCPReceiverReport.cpp
        mod/rtp/RTCPReceiverReport.h
        mod/rtp/RTCPReport.cpp
        mod/rtp/RTCPReport.h
        mod/rtp/RTCPRTPFeedback.cpp
        mod/rtp/RTCPRTPFeedback.h
        mod/rtp/RTCPSDES.cpp
        mod/rtp/RTCPSDES.h
        mod/rtp/RTCPSenderReport.cpp
        mod/rtp/RTCPSenderReport.h
        mod/rtp/RTPDepacketizer.cpp
        mod/rtp/RTPDepacketizer.h
        mod/rtp/RTPHeader.h
        mod/rtp/RTPHeader.cpp
        mod/rtp/RTPHeaderExtension.h
        mod/rtp/RTPHeaderExtension.cpp
        mod/rtp/RTPMap.cpp
        mod/rtp/RTPMap.h
        mod/rtp/RTPPacket.h
        mod/rtp/RTPPacket.cpp

        mod/vp8/vp8.h
        mod/vp8/vp8depacketizer.h
        mod/vp8/vp8depacketizer.cpp

        mod/h264/h264.h
        mod/h264/h264decoder.cpp
        mod/h264/h264decoder.h
        mod/h264/h264depacketizer.cpp
        mod/h264/h264depacketizer.h
        mod/h264/h264encoder.cpp
        mod/h264/h264encoder.h

        mod/audio.h
        mod/bitstream.h
        mod/codecs.h
        mod/config.h
        mod/log.h
        mod/media.h
        mod/rtp.h
        mod/tools.h
        mod/version.h
        mod/video.h
)

set(TRANSFMT_SOURCES
        dbg.hpp
        media_hapi.h
        packet.hpp
        packet_reorder.hpp
        rav_record.h
        rav_record.cc
        rtp_pre_proc.cpp
        rtp_pre_proc.hpp
        rtp_reader.hpp
        rtp_reader.cpp
        rtp_writer.hpp
        rtp_writer.cpp
        timestamp.cpp
        timestamp.hpp
        tlv.hpp
        tlv.cpp
        util.h
        packet.cpp
        xvideo_util.hpp
        xvideo_util.cpp)

find_package(PkgConfig REQUIRED)
pkg_check_modules(VPX REQUIRED vpx)
pkg_check_modules(AVCODEC REQUIRED libavcodec)
pkg_check_modules(AVFORMAT REQUIRED libavformat)
pkg_check_modules(AVUTIL REQUIRED libavutil)
pkg_check_modules(SWS REQUIRED libswscale)
pkg_check_modules(LOG4CPLUS REQUIRED log4cplus)
pkg_check_modules(OPUS REQUIRED opus)
pkg_check_modules(X264 REQUIRED x264)
pkg_check_modules(SRTP REQUIRED libsrtp2)

message("AVCODEC_INCLUDE_DIRS is ${AVCODEC_INCLUDE_DIRS}")
message("AVCODEC_LIBRARY_DIRS is ${AVCODEC_LIBRARY_DIRS}")
message("X264_INCLUDE_DIRS is ${X264_INCLUDE_DIRS}")
message("X264_LIBRARY_DIRS is ${X264_LIBRARY_DIRS}")

include_directories(
        ${CMAKE_CURRENT_BINARY_DIR}
        ${VPX_INCLUDE_DIRS}
        ${AVCODEC_INCLUDE_DIRS}
        ${AVFORMAT_INCLUDE_DIRS}
        ${AVUTIL_INCLUDE_DIRS}
        ${SWS_INCLUDE_DIRS}
        ${LOG4CPLUS_INCLUDE_DIRS}
        ${OPUS_INCLUDE_DIRS}
        ${X264_INCLUDE_DIRS}
        ${SRTP_INCLUDE_DIRS}
        .
        mod
        mod/rtp
        mod/vp8
        mod/h264
        stage/include/
        )

link_directories(
    ${VPX_LIBRARY_DIRS}
    ${AVCODEC_LIBRARY_DIRS}
    ${AVFORMAT_LIBRARY_DIRS}
    ${AVUTIL_LIBRARY_DIRS}
    ${SWS_LIBRARY_DIRS}
    ${LOG4CPLUS_LIBRARY_DIRS}
    ${OPUS_LIBRARY_DIRS}
    ${X264_LIBRARY_DIRS}
    ${CMAKE_SOURCE_DIR}/stage/lib/
)

message("AVCODEC_LDFLAGS=${AVCODEC_LDFLAGS}")
message("AVCODEC_STATIC_LIBRARIES=${AVCODEC_STATIC_LIBRARIES}")
message("AVCODEC_STATIC_OTHER_LDFLAGS=${AVCODEC_STATIC_OTHER_LDFLAGS}")

add_executable(transfmt ${MEDOOZE_SOURCES} ${TRANSFMT_SOURCES} ${RTP_SOURCES} main_transfmt.cc)

target_link_libraries(transfmt
        ${VPX_STATIC_LIBRARIES}
        ${X264_STATIC_LIBRARIES}
        ${AVCODEC_STATIC_LIBRARIES}
        ${AVFORMAT_STATIC_LIBRARIES}
        ${AVUTIL_STATIC_LIBRARIES}
        ${SWS_STATIC_LIBRARIES}
        ${GLIB_LDFLAGS}
        ${OPENSSL_LDFLAGS}
        ${SRTP_LDFLAGS}
        ${LOG4CPLUS_STATIC_LIBRARIES} -lpthread
        ${OPUS_STATIC_LIBRARIES}
        -lmp3lame
        -ldl)

if (APPLE)
    set_target_properties(transfmt PROPERTIES LINK_FLAGS "-framework CoreFoundation \
    -framework CoreServices -framework QuartzCore -framework VideoDecodeAcceleration")
endif (APPLE)

install(TARGETS transfmt DESTINATION bin)

install(FILES test/sample.tlv DESTINATION test)

install(PROGRAMS scripts/config.sh
                 scripts/log.sh
                 scripts/scanner.sh
                 scripts/scanner_test.sh
                 scripts/merge_scanner.sh
        DESTINATION bin)


#add_executable(test_nack ../../../src/nack_handler.cpp ../../../src/nack_handler.hpp)